package sdcncsi.ict.counter.web;

import java.awt.Color;
import java.util.Map;

import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.springframework.web.servlet.view.AbstractView;


public class TextView extends AbstractView {

	//渲染输出方法
	protected void renderMergedOutputModel(Map dataMap, HttpServletRequest request, 
			HttpServletResponse response)
			throws Exception {
		//设定response属性
		response.setContentType("text/html");
		response.setHeader("Pragma", "No-cache");
		response.setHeader("Cache-Control", "no-cache");
		response.setDateHeader("Expires", 0);
		
		//计数值，或者错误提示
		StringBuffer messageBuf = new StringBuffer(256);
		messageBuf.append("<html><head></head>");
		messageBuf.append("<body bgcolor=\""+ColorTool.getRandColorString(200, 250)+"\">");
		messageBuf.append("<font style=\"font-family:Times New Roman;font-size: 18px;\"");
		if((Boolean)dataMap.get("result")){
			messageBuf.append(" color=\""+ColorTool.getRandColorString(10, 60)+"\">");
			messageBuf.append(dataMap.get("count").toString());//得到计数 
		}else{
			messageBuf.append(" color=\""+Color.RED+"\">");
			messageBuf.append("Error");
		}
		messageBuf.append("</font></body></html>");
		ServletOutputStream responseOutputStream = response.getOutputStream();
		responseOutputStream.println(messageBuf.toString());
		//以下关闭输入流！
		responseOutputStream.flush();
		responseOutputStream.close();
	}

}
